<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;

class BaseActiveRecord extends \yii\db\ActiveRecord
{
    /**
     * 记录时间自动维护
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['ctime', 'lutime'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['lutime'],
                ],
                // if you're using datetime instead of UNIX timestamp:
                // 'value' => new Expression('NOW()'),
                'value' => function(){return date('Y-m-d H:i:s',time());},
            ],
        ];
    }

}
